const express = require("express");
const router = express.Router();

const searchModel = require("../../model/searchModel");

//获取新闻搜索列表
router.post("/searchnews", (req, res) => {
    let { searchVal } = req.body;
    // console.log(searchVal);
    searchModel
        .getSearchList({ searchVal })
        .then((data) => {
            res.send({
                code: 200,
                msg: "获取搜索列表成功",
                data,
            });
        })
        .catch((err) => {
            res.send({
                code: -3,
                msg: "获取搜索列表失败",
                err,
            });
        });
});

//获取新闻主题列表
router.post("/categorynews", (req, res) => {
    let { newsCategory } = req.body;
    searchModel
        .getCategoryList({ newsCategory })
        .then((data) => {
            res.send({
                code: 200,
                msg: "获取主题列表成功",
                data,
            });
        })
        .catch((err) => {
            res.send({
                code: -1,
                msg: "获取主题列表失败",
                err,
            });
        });
});

module.exports = router;
